///////////////////////////////////////////////////////////////
//
// FileName : KMyHashTable.h
// Creator : Tan Menglong
// Date : 2009/07/16 14:45:39
// Comment : HashTable.
//
///////////////////////////////////////////////////////////////

#include <afx.h>

namespace KMySTL
{
	static const unsigned int gs_nPrimeTable[] =
	{
		53, 97, 193, 389, 769, 1543, 3079, 6151,
		12289, 24593, 49157, 98317,
		196613, 393241, 786433, 1572869,
		3145739, 6291469, 12582917, 25165843,
		50331653, 100663319, 201326611, 402653189,
		805306457, 1610612741
	};

	static const unsigned int gs_nPrimeTableLength =
		sizeof(gs_nPrimeTable) / sizeof(gs_nPrimeTable[0]);

	static const float gs_fMaxLoadFactor = 0.65f;

	template<class T>
	class KMyHashTable: public CObject
	{
	protected:
#ifdef _DEBUG
		virtual void AssertValid(const KMyHashTable<T>* pkObj) const
		{
			assert(pkObj);
		}
#endif

	public:
		KMyHashTable(void)
		{

		}

		KMyHashTable(const KMyHashTable& kOther)
		{

		}

		virtual ~KMyHashTable(void)
		{

		}

		const KMyHashTable& operator=(const KMyHashTable& kOther)
		{

		}

		unsigned long Hash(char* szKey, unsigned int nKeylength)
		{
			unsigned long h = 0, g;
			char *arend=szKey+nKeylength; 
			while (szKey < arend)
			{
				h = (h << 4) + *szKey++; 
				if ((g = (h & 0xf0000000))) { 
					h = h ^ (g >> 24); 
					h = h ^ g; 
				} 
			} 
			return h; 
		}
	};
}